﻿/*
LineChart：
dom：图表渲染容器
xData：x轴
yData:数据
linetitle：标题（默认值为空）
maxy：最大值（与plotLines配合使用）
plotLines:基准线
*/

function TransverseChart(TranCharto) {
    this.lineSChartDom = lineCharto.dom;
    this.linetitle = lineCharto.linetitle ? lineCharto.linetitle : " ";
    this.linetitleD = lineCharto.linetitleD ? lineCharto.linetitleD :"";
    this.linetitleDClass = lineCharto.linetitleDClass ? lineCharto.linetitleDClass :"";
    this.xData = lineCharto.xData;
    this.yData = lineCharto.yData;
    this.maxy = lineCharto.maxy ? lineCharto.maxy : null;
    this.plotLines = lineCharto.plotLines != null ? lineCharto.plotLines : "null";
    this.plotlineid = lineCharto.plotlineid ? lineCharto.plotlineid : "plotline";
    this.enabled = lineCharto.enabled != null ? lineCharto.enabled : true;
    var self = this;
    var isstringEmpty = self.linetitleDClass == "" ? false : true;
  
    return new Highcharts.Chart({
        chart: {
            renderTo: self.lineSChartDom,
            defaultSeriesType: 'line'
        },
        title: {
            text: "<div class='" + self.linetitleDClass + "' alt='" + self.linetitleD + "' style='display: block;' onmouseover='if(" + isstringEmpty + "){showF(this);}' onmouseout='if(" + isstringEmpty + "){hideF();}'>" + self.linetitle + "</div>",
            useHTML:true,
            style: {
                color: "#3b7197",
                fontWeight: 'bold'
            },
            y: 10
        },
        subtitle: {
            text: ''
        },
        xAxis: [{
            lineWidth: 2,
            lineColor: '#6a6a6a',
            categories: self.xData,
            labels: {
                tickPixelInterval: 94,
                staggerLines: 2,
                style: {
                    color: '#414C59'
                }
            }
        }],
        yAxis: {
            gridLineWidth: 0,
            lineWidth: 2,
            lineColor: '#6a6a6a',
            max: self.maxy,
            min: 0,
            title: {
                text: '单位（件）',
                align: 'high',
                offset: 0,
                rotation: 0,
                y: -10,
                x: 10
            },
            plotLines: [{
                value: self.plotLines,
                width: 2,
                color: '#a8bfeb',
                label: {
                    text: "指标(" + self.plotLines + "件)",
                    align: 'left',
                    verticalAlign: 'bottom',
                    style: {
                        color: '#a8bfeb'
                    }
                },
                id: self.plotlineid
            }]
        },
        colors: ["#feb754", "#9ddc6d", "#84bbf3"],
        plotOptions: {
            series: {
                animation: false
            }
        },
        credits: {
            enabled: false
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y;
            }
        },
        legend: {
            align: 'right',
            layout: 'vertical',
            verticalAlign: 'top',
            floating: false,
            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
            borderWidth: 0,
            enabled: self.enabled,
            shadow: true
        },
        series: self.yData
    });
}

/*年度切换事件*/
function toggleYear(timeyear, linechart, fmyData, fmtargetdata, lastTarget, lastfmyData, plotline, self, title) {
    var j = timeyear.index($(self));
    if (selcyear != j) {
        selcyear = j;
    }
    if (j == 0) {
     
        if ($("#yearData").val() == "") {
            alert("对不起今年数据为空！");
        } else {
            timeyear.removeClass("time-selct");
            linechart.showLoading("loading...");
            $(timeyear[j]).addClass("time-selct");
            linetitle = year + title;
            for (var i = 0; i < linechart.series[0].data.length; i++) {
                linechart.series[0].setData(fmyData);
                linechart.hideLoading();
            }
            plotLinesdata = fmtargetdata;
         
        }

    } else {
        if (lastTarget == "") {
            alert("对不起去年数据为空！");
        } else {
            timeyear.removeClass("time-selct");
            linechart.showLoading("loading...");
            $(timeyear[j]).addClass("time-selct");
            linetitle = (year - 1) + title;
            for (var i = 0; i <12; i++) {
                linechart.series[0].setData(lastfmyData);
                linechart.hideLoading();
            }
            plotLinesdata = lastTarget;
        }
    }
    linechart.setTitle({ text: linetitle });
    linechart.yAxis[0].removePlotLine(plotline);

    linechart.yAxis[0].addPlotLine({
        value: plotLinesdata,
        color: '#a8bfeb',
        width: 2,
        id: plotline,
        label: {
            text: "指标(" + plotLinesdata + "件)",
            align: 'left',
            verticalAlign: 'bottom',
            style: {
                color: '#a8bfeb'
            }
        }
    });
}
